by Ayan Chaudhuri (8 Submissions)
Category: Custom Controls/Forms/Menus
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Sat 2nd February 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Close Your Active Form simply Pressing the
Returns or sets a value indicating whether a command button is the Cancel button on a form. This command button can be the CommandButton control or any object within an OLE container control that behaves as a command button.
Only one CommandButton control on a form can be the Cancel button. When the Cancel property is set to True for one CommandButton, it's automatically set to False for all other CommandButton controls on the form. When a CommandButton control's Cancel property setting is True and the form is the active form, the user can choose the CommandButton by clicking it, pressing the ESC key, or pressing ENTER when the button has thefocus.
For OLE container controls, the Cancel property is provided only for those objects that specifically behave as command buttons.
For a form that supports irreversible operations, such as deletions, it's a good idea to make the Cancel button the default button. To do this, set both the Cancel property and the Default property to True.
Syntax
object.Cancel [= boolean]
No Declaration:
Code:
Private Sub Command1_Click()
' *** Close form when the escape key is pressed ***
' *** When Command1 <Command Button> Cancel Property is set to True ***
Unload Me
End Sub